<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.student.dao.StudentDao" %>
<%@ page import="com.student.model.Student" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加学生结果</title>
    <style>
        .result {
            width: 400px;
            margin: 20px auto;
            padding: 20px;
            text-align: center;
        }
        .success {
            color: #4CAF50;
        }
        .error {
            color: #f44336;
        }
    </style>
</head>
<body>
    <div class="result">
        <%
        request.setCharacterEncoding("UTF-8");
        
        try {
            int id = Integer.parseInt(request.getParameter("id"));
            String name = request.getParameter("name");
            String sex = request.getParameter("sex");
            int age = request.getParameter("age") != null && !request.getParameter("age").isEmpty() ? 
                     Integer.parseInt(request.getParameter("age")) : 0;
            double weight = request.getParameter("weight") != null && !request.getParameter("weight").isEmpty() ? 
                          Double.parseDouble(request.getParameter("weight")) : 0.0;
            double height = request.getParameter("height") != null && !request.getParameter("height").isEmpty() ? 
                          Double.parseDouble(request.getParameter("height")) : 0.0;
            
            Student student = new Student(id, name, sex, age, weight, height);
            StudentDao dao = new StudentDao();
            
            if(dao.addStudent(student)) {
                out.println("<h2 class='success'>添加成功！</h2>");
            } else {
                out.println("<h2 class='error'>添加失败！</h2>");
            }
        } catch(Exception e) {
            out.println("<h2 class='error'>添加失败：" + e.getMessage() + "</h2>");
        }
        %>
    </div>
</body>
</html> 